package com.itcast.controller;


import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
@RequestMapping("/file")
public class UpLoadController {

    @RequestMapping("/upload")
    public String findUpload(MultipartFile upload) throws IOException {
        //创建客户端用于上传文件
        Client client =  Client.create();

        //设置客户端路径
        String path = "http://localhost:8090/upload/";

        //获取上传路径
        String filename = upload.getOriginalFilename();
        //文件上传
        WebResource resource = client.resource(path + filename);
        //将文件传入对应路径
        resource.put(upload.getBytes());
        return "success";
    }
}
